package net.bingosoft.common.data;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 2007-12-10 下午12:39:28
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:数据对象的基类
 * ChangeLog:
 */
public abstract class BaseDataBean implements Serializable{
	public abstract Object getId();
	
	@Override
	public String toString(){
		String selfDescription = null;
		try{
			selfDescription = ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
		}catch(Exception ex){
			selfDescription = super.toString();
		}
		return selfDescription;
	}
	
	@Override
	public boolean equals(Object other) {
		if (!(other instanceof BaseDataBean)){
			return false;
		}
		BaseDataBean castOther = (BaseDataBean) other;
		if (this.getId() == null && castOther.getId() == null)
			return false;
		return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
	}
	
	@Override
	public int hashCode() {
		if(this.getId()!= null){
			return this.getId().hashCode();
		}
		return super.hashCode();
	}
	
	
}
